﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Data.Entities;

namespace Proggy.Data.Abstract
{
    /// <summary>
    /// Membership data repository
    /// </summary>
    public interface IMembershipDataRepository
    {
        /// <summary>
        /// Membership groups
        /// </summary>
        IQueryable<Group> Groups { get; }

        /// <summary>
        /// Groups members
        /// </summary>
        IQueryable<GroupMember> GroupMembers { get; }

        /// <summary>
        /// Returns all groups for this member's username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        IEnumerable<Group> GetGroupsForMember(string username);

        /// <summary>
        /// Returns FormsAuthenticationMember or null
        /// </summary>
        /// <param name="username"></param>
        /// <param name="activeOnly"></param>
        /// <returns></returns>
        FormsAuthenticationMember GetFormsAuthenticationMemberFromUsername(string username, bool activeOnly);

        /// <summary>
        /// Returns all forms authentication members (use sparingly)
        /// </summary>
        /// <returns></returns>
        IQueryable<FormsAuthenticationMember> GetAllFormsAuthenticationMembers();

        /// <summary>
        /// Change password
        /// </summary>
        /// <param name="currentUsername"></param>
        /// <param name="newPassword"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetChangePasswordOk(string currentUsername, string currentPassword, string newPassword, ref string errorMsg);

        /// <summary>
        /// Check validity of password
        /// </summary>
        /// <param name="password"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool PasswordIsValid(string password, ref string errorMsg);

        /// <summary>
        /// Try update password
        /// </summary>
        /// <param name="member"></param>
        /// <param name="newPassword"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool UpdatePasswordOk(FormsAuthenticationMember member, string newPassword, ref string errorMsg);

        /// <summary>
        /// Sets last login
        /// </summary>
        /// <param name="member"></param>
        void SetLastLogon(FormsAuthenticationMember member);

        /// <summary>
        /// Register new member
        /// </summary>
        /// <param name="saveData">If false, no data will be saved (use as a check)</param>
        /// <param name="name"></param>
        /// <param name="username"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="guid"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetRegisterNewMemberOk(bool saveData, string name, string username, string email, string password, Guid guid, ref string errorMsg);

        /// <summary>
        /// Activate membership
        /// </summary>
        /// <param name="activationCode"></param>
        /// <returns></returns>
        void ActivateMembership(string activationCode);

        /// <summary>
        /// Reset password
        /// </summary>
        /// <param name="emailAddress"></param>
        /// <param name="newPassword"></param>
        /// <param name="username"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool GetResetPasswordOk(string emailAddress, string newPassword, ref string username, ref string errorMsg);

        /// <summary>
        /// Returns member
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        FormsAuthenticationMember GetMemberByEmailAddress(string email);

        /// <summary>
        /// Forms members
        /// </summary>
        IQueryable<FormsAuthenticationMember> FormsAuthenticationMembers { get; }

        /// <summary>
        /// Add member to group
        /// </summary>
        /// <param name="group"></param>
        /// <param name="memb"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool AddMemberToGroup(Group group, string memb, string currentUsername, ref string errorMsg);

        /// <summary>
        /// Remove group member
        /// </summary>
        /// <param name="groupMemberId"></param>
        void RemoveGroupMember(int groupMemberId);

        /// <summary>
        /// Add group
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        bool AddGroup(string groupName, string currentUsername, ref string errorMsg);
    }
}
